package cn.kgc.web.controller;

import cn.kgc.base.entity.Group;
import cn.kgc.base.utils.ResponseResult;
import cn.kgc.web.service.GroupService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 课工场
 * @date 2024/1/11
 * @description
 */
@RestController
@RequestMapping("group")
public class GroupController {

    @Resource
    private GroupService groupService;

    // 获取小组列表
    @GetMapping
    public  ResponseResult   groupList(){
        return groupService.groupList();
    }


    // 根据id 获取小组信息
    @GetMapping("{id}")
    public Group   getGroupById(@PathVariable("id") Integer id){
        Group group = groupService.getById(id);
        return group;
    }

    // 添加小组信息
    @PostMapping
    public ResponseResult   addGroup(@RequestBody Group group){
        group.setCreatedate(new Date());
        groupService.save(group);
        return ResponseResult.success().data(group).message("添加小组成功");
    }

}
